package com.example.demo.lc;

/**
 * @Description 完美数
 * @Author wzh
 * @Date 2021/10/19 2:06 下午
 * @Version 1.0
 * https://leetcode-cn.com/problems/perfect-number/
 */
public class Leetcode507 {
    public static void main(String[] args) {
        //System.out.println(checkPerfectNumber(28));
        //System.out.println(checkPerfectNumber(6));
        //System.out.println(checkPerfectNumber(8128));

    }

    public static boolean checkPerfectNumber(int num) {
        if(num == 1){
            return false;
        }
        int sum = 1;
        for (int i = 2; i * i <= num; i++) {
            if (num % i == 0) {
                sum += i;
                if (i * i != num) {
                    sum += num / i;
                }
            }
        }
        return sum == num;
    }
}
